package echat.future.cn.echat.my.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.databinding.ActivityWalletBinding;
import echat.future.cn.echat.my.adapter.MeJumpAdapter;
import echat.future.cn.echat.my.adapter.MyJumpDecoration;
import echat.future.cn.echat.my.api.UserApi;
import echat.future.cn.echat.my.bean.MeJumpBean;
import echat.future.cn.echat.my.bean.WalletInfo;
import echat.future.cn.echat.my.utils.HttpUtilsRequst;
import echat.future.cn.echat.my.utils.RouterHelper;
import echat.future.cn.echat.my.utils.StatusBarUtils;
import echat.future.cn.echat.my.utils.UserHelper;
import echat.future.cn.echat.my.weight.Navagation.IBaseNavagation;

public class WalletActivity extends BaseActivity<ActivityWalletBinding>{

    MeJumpAdapter meJumpAdapter;
    List<MeJumpBean> mDatas = new ArrayList<>();

    @Override
    public int layoutId() {
        return R.layout.activity_wallet;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtils.hideStatus(this);
    }

    @Override
    public IBaseNavagation navagation() {
        return null;
    }

    @Override
    public void initView() {
        bind.coinNumber.setText(UserHelper.getUser().getE_money()+"");
        meJumpAdapter = new MeJumpAdapter(this.mDatas);
        bind.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        bind.recyclerView.setAdapter(meJumpAdapter);
        bind.recyclerView.addItemDecoration(new MyJumpDecoration(this,1,getResources().getColor(R.color.color_0E0F1A)));
        meJumpAdapter.setOnItemClickListener((adapter, view, position) -> {
            if(position == 0){
                startActivity(new Intent(WalletActivity.this,CapitalActivity.class).putExtra(CapitalActivity.EXTRA_TYPE,CapitalActivity.TYPE_INCOME));
            }else if(position == 1){
                startActivity(new Intent(WalletActivity.this,CapitalActivity.class).putExtra(CapitalActivity.EXTRA_TYPE,CapitalActivity.TYPE_EXOEBDITURE));
            }else{
                startActivity(new Intent(WalletActivity.this,WithdrawHistoryActivity.class));
            }
        });
        loadMenue();

        bind.llRecharge.setOnClickListener(v -> {
            RechargeActivity.openActivity(this,RechargeActivity.class);
        });
        bind.llWithdraw.setOnClickListener(v -> {
            RechargeActivity.openActivity(this,WithdrawActivity.class);
        });
    }

    private void loadMenue(){
        mDatas.add(new MeJumpBean("收入明细",R.mipmap.qianbao_shouru,"收入"));
        mDatas.add(new MeJumpBean("支出明细",R.mipmap.qianbao_zhichu,"收入"));
        mDatas.add(new MeJumpBean("提现明细",R.mipmap.qianbao_mingxi,"收入"));
    }

    @Override
    protected void onResume() {
        super.onResume();
        loadData();
    }
    WalletInfo mwalletInfo;
    private void loadData(){
        new HttpUtilsRequst<>(this,HttpUtilsRequst.retrofitClient.create(UserApi.class).getMoney(UserHelper.getToken()))
                .setmOnRequstSuccessListener(new HttpUtilsRequst.OnRequstSuccessListener<WalletInfo>() {
                    @Override
                    public void onSuccss(WalletInfo o) {
                        mwalletInfo = o;
                        bind.coinNumber.setText(mwalletInfo.getWallet()+"");
                    }
                })
                .start();
    }
}
